home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / pserv.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1998-10-27  |  1.7 KB  |  67 lines

  1. /*
  2.     This macro shows how to write a very simple tcp service
  3.     to be called by inetd.
  4.     To use this service, you must:
  5.     - be sure you copied "rxs" from rxsocket.lha to C:
  6.     - copy pserv.rexx TO ram:
  7.     - add to the services database:
  8.         ARexxRevServ 4000/tcp
  9.     - add to the inedt database:
  10.         ARexxRevServ stream tcp nowait root c:rxs rxs ram:pserv.rexx
  11.     (port number 4000 can be changed to any free tcp port).
  12.     To test the service just use revclient.
  13.     if the env var "PSERV_LOG" is set to 1, it logs the connection.
  14. */
  15.  
  16. if ~show("L","rexxsupport.library") then
  17.     if ~addlib("rexxsupport.library",0,-30) then do
  18.         say "no rexxsupport.library"
  19.         exit
  20.     end
  21. if ~show("L","rxsocket.library") then
  22.     if ~addlib("rxsocket.library",0,-30) then do
  23.         say "no rxsocket.library"
  24.         exit
  25.     end
  26. if ~show("L","rmh.library") then
  27.     if ~addlib("rmh.library",0,-30) then do
  28.         say "no rmh.library"
  29.         exit
  30.     end
  31.  
  32. prg = ProgramName("NOEXT")
  33.  
  34. /* Here we test if socket number 0 exists.
  35.    If it does we were called from inetd.
  36.    If it doesn't, we weren't called from inetd and we exit. */
  37. if ~IsSocket(0) then do
  38.     say prg": this service must be run from rxs in inedt"
  39.     exit
  40. end
  41.  
  42. /* who connected us? Let's try to get info, if error log that */
  43. if ~GetSockName(0,"NAME")<0 then do
  44.     call SysLog(prg "Can't get peer info ("errno()")")
  45.     exit
  46. end
  47.  
  48. if getclip("PSERV_LOG")==1 then do
  49.     /* log the connection */
  50.     msg = "pserv Connection from" name.addrAddr
  51.     if GetHostByAddr("HOST",name.addrAddr) then msg = msg  "("host.hostName")"
  52.     call SysLog(msg)
  53. end
  54.  
  55. /* the service itself */
  56. len = recv(0,"BUF",256)
  57. if len<0 then do
  58.     call SysLog("pserv Error reading ("errno()")")
  59.     exit
  60. end
  61.  
  62. buf = reverse(buf)
  63. if send(0,BUF)~=length(buf) then do
  64.     call SysLog("pserv Error sending ("errno()")")
  65.     exit
  66. end
  67.